package org.example.Server.controller.homework;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.homework.HmkGradeComment;
import org.example.Server.model.homework.HmkOutRule;
import org.example.Server.model.homework.HmkStuGradeDTO;
import org.example.Server.service.homework.TeacherHomeworkService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/youxich/homework/teacher/grade")
public class TeacherHmkGradeController {
    @Autowired
    TeacherHomeworkService teacherHomeworkService;

    /**
     * 获取学生作业情况列表
     *
     * @param homework_id
     * @param is_grade      教师是否批阅 0未批阅1已批阅
     * @param submit_status 学生提交状态 0未提交1按时提交2补交
     * @param division_id   分班id
     * @return
     */
    @GetMapping()
    public ResultAPI getHmkGradeList(@RequestParam Integer homework_id,
                                     @RequestParam(required = false) Integer is_grade,
                                     @RequestParam(required = false) Integer submit_status,
                                     @RequestParam(required = false) Integer division_id) {
        return teacherHomeworkService.getHmkGradeList(homework_id, is_grade, submit_status, division_id);
    }

    /**
     * 根据学生作业id获取作业详情
     *
     * @param stu_hmwk_id
     * @return
     */
    @GetMapping({"/{stu_hmwk_id}"})
    public ResultAPI getStuHmk(@PathVariable Integer stu_hmwk_id) {
        return teacherHomeworkService.getStuHmk(stu_hmwk_id);
    }

    /**
     * 添加作业评分以及评论（学生、老师、助教）
     *
     * @param stu_hmwk_id
     * @return
     */
    @PostMapping({"/{stu_hmwk_id}"})
    public ResultAPI addTechHmkCommentandGrade(@PathVariable Integer stu_hmwk_id, @RequestBody HmkStuGradeDTO hmkStuGradeDTO) {
        hmkStuGradeDTO.setStu_hmwk_id(stu_hmwk_id);
        return teacherHomeworkService.addHmkGrade(hmkStuGradeDTO);
    }

    /**
     * 查看某作业评阅列表
     *
     * @param stu_hmwk_id
     * @return
     */
    @GetMapping("/comment/{stu_hmwk_id}")
    public ResultAPI getCommentList(@PathVariable Integer stu_hmwk_id) {
        return teacherHomeworkService.getGradeCommentList(stu_hmwk_id);
    }

    /**
     * 教师以及助教调分（脱离得分占比系统
     *
     * @param hmkOutRule
     * @return
     */
    @PutMapping
    public ResultAPI updateGradeByTech(@RequestBody HmkOutRule hmkOutRule) {
        return teacherHomeworkService.updateGradeByTech(hmkOutRule);
    }
}
